using System;

namespace Sunny.UI;

public abstract class BaseLogger : ILogger
{
	public LogLevel Level { get; set; } = LogLevel.Off;


	public void Trace(params object[] args)
	{
		if (LogLevel.Trace >= Level)
		{
			WriteLog(LogLevel.Trace, GenerateLog(LogLevel.Trace, args));
		}
	}

	public void Debug(params object[] args)
	{
		if (LogLevel.Debug >= Level)
		{
			WriteLog(LogLevel.Debug, GenerateLog(LogLevel.Debug, args));
		}
	}

	public void Info(params object[] args)
	{
		if (LogLevel.Info >= Level)
		{
			WriteLog(LogLevel.Info, GenerateLog(LogLevel.Info, args));
		}
	}

	public void Warn(params object[] args)
	{
		if (LogLevel.Warn >= Level)
		{
			WriteLog(LogLevel.Warn, GenerateLog(LogLevel.Warn, args));
		}
	}

	public void Error(params object[] args)
	{
		if (LogLevel.Error >= Level)
		{
			WriteLog(LogLevel.Error, GenerateLog(LogLevel.Error, args));
		}
	}

	public void Fatal(params object[] args)
	{
		if (LogLevel.Fatal >= Level)
		{
			WriteLog(LogLevel.Fatal, GenerateLog(LogLevel.Fatal, args));
		}
	}

	public string GenerateLog(LogLevel level, params object[] args)
	{
		return DateTime.Now.DateTimeExString() + " | " + level.Description() + " | " + string.Join(",", args);
	}

	public abstract void WriteLog(string log);

	public virtual void WriteLog(LogLevel level, string log)
	{
		WriteLog(log);
	}
}
